//
//  FoatPointExtension.swift
//  XWHAOfflineFitting
//
//  Created by edy on 2024/3/5.
//

import Foundation


public extension FloatingPoint {
    
    var cleanZeroFormatted: String {
        getCleanZerFormattedString(maximumFractionDigits: 1)
    }
    
    func getCleanZerFormattedString(maximumFractionDigits: Int) -> String {
        let formatter = NumberFormatter()
        formatter.numberStyle = .decimal
        // you can set the minimum fraction digits to 0
        formatter.minimumFractionDigits = 0
        // and set the maximum fraction digits to 1
        formatter.maximumFractionDigits = maximumFractionDigits
        return formatter.string(for: self) ?? ""
    }
    
}

public extension Float {
    
    /// 清除后面的的字符
    var cleanZeroString: String {
        return self.truncatingRemainder(dividingBy: 1) == 0 ? String(format: "%.0f", self) : String(self)
    }
    
}

public extension Double {
    
    /// 清除后面的的字符
    var cleanZeroString: String {
        return self.truncatingRemainder(dividingBy: 1) == 0 ? String(format: "%.0f", self) : String(self)
    }
    
}
